/*
 * Copyright@www.it1997.com.
 * @Author: 陈晓晨
 * @Date: 2020/6/10
 * Description:版权所有 QQ:376231445
 */

package com.it1997.it1997admin.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultUtil {
    protected static final Integer FAIL_CODE = 1;
    protected static final Integer SUCCESS_CODE = 0;
    //响应吗
    protected Integer code;
    //响应信息
    protected String message;
    //响应数据
    protected Object data;
    public static String  success(Integer code,String message,Object data){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",code);
        jsonObject.put("message",message);
        jsonObject.put("data",data);
        return JSON.toJSONString(jsonObject);
    }
    public static String  success(Integer code,String message){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",code);
        jsonObject.put("message",message);
        return JSON.toJSONString(jsonObject);
    }
    public static String fail(Integer code,String message,Object data){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",code);
        jsonObject.put("message",message);
        jsonObject.put("data",data);
        return JSON.toJSONString(jsonObject);
    }
    public static String fail(Integer code,String message){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",code);
        jsonObject.put("msg",message);

        return JSON.toJSONString(jsonObject);
    }
    public static String tableData(Integer code,String message,Integer count,Object data){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code",code);
        jsonObject.put("message",message);
        jsonObject.put("count",count);
        jsonObject.put("data",data);
        return JSON.toJSONString(jsonObject);
    }
}
